<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                                  |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                     |
// +------------------------------------------------------------------------+
// | Author: anguolei@clcw.com.cn                                           |
// +------------------------------------------------------------------------+
//
/**
 * 卖车用户
 */
namespace AuctionBack\Controller;

use AuctionCore\CarOwner\OwnerUserList as OwnerUserList;
use AuctionCore\System\AuctionException;
use AuctionCore\CarOwner\Owner;
use AuctionCore\System\SystemLog;
use AuctionCore\Common\AjaxPage;


class UserController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->emp_id = $this->user_info['emp_id'];
    }


    public function index(){
        $this->display();
    }

    /**
     * 用户列表
     * @author angl
     */
    public function user_list()
    {
        $p = I('get.p/d',1);
        $limit = I('get.page_size',10);
        $params = [];
        $params['uid'] = I('request.uid/d', 0);
        $params['user_name'] = I('request.user_name', '');
        $params['real_name'] = I('request.real_name', '');
        $params['phone'] = I('request.phone', '');
        $params['status'] = I('request.status',-1);
        $params['start_time'] = I('request.start_time','');
        $params['end_time'] = I('request.end_time','');

        $oul = new OwnerUserList();
        $list = $oul->get($limit, $p, $params);
        $count = $oul->count($params);

        $Page = new AjaxPage($count, $limit, "get_page");
        $Page->setConfig('theme', " %totalRow% %header% %nowPage%/%totalPage% 页 %first% %upPage% %prePage% %linkPage% %downPage% %nextPage% %end% %jumpform%");
        $show = $Page->show();   // 分页显示输出
        //dump($list);exit;
        $this->assign('params', $params);
        $this->assign('list', $list);
        $this->assign('p', $p);
        $this->assign('page', $show);
        $this->display();
    }

    /**
     * 操作
     * @author sam
     */
    public function ci_op()
    {
        try {
            $username = $_POST['username'];
            $op_type = $_POST['op_type'];

            // dump($_POST);exit;
            if ($op_type == '3') {
                $this->ch_pasword_and_send($username);
            } else {
                $fu = new \AuctionCore\Account\FrontUser($username);
                if ($op_type === '0') {      //启用
                    $fu->enable();
                } else if ($op_type === '1') {  //禁用
                    $fu->disable();
                }
            }
            echo \AuctionCore\Common\Util::auto_jsonp_or_json($_REQUEST, array('code' => 200, 'msg' => '', 'data' => ''));
            exit;
        } catch (AuctionException $e) {
            echo \AuctionCore\Common\Util::auto_jsonp_or_json($_REQUEST, array('msg' => $e->getMessage(), 'code' => $e->getCode()));
            exit;
        }
    }

    //更新帐号密码,并发送给车主
    private function ch_pasword_and_send($uid)
    {

        $detail = Owner::get_owner_by_uid($uid);
        $mobile = $detail['phone'];
        $new_password = rand(100000, 999999);

        //更新帐号密码
        $fu = new \AuctionCore\Account\FrontUser($uid);
        $fu->reset_password();
        /*$user_info = $fu->user_info();
        $mobile = $user_info['pwd_mobile'];
        $ok = $fu->change_password($new_password);*/

    }
}